package vip.xiaonuo.supplier.modular.warehouse.storages.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.lang.tree.Tree;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.supplier.modular.base.stores.entity.SupplierStores;
import vip.xiaonuo.supplier.modular.warehouse.storages.entity.SupplierStorages;
import vip.xiaonuo.supplier.modular.warehouse.storages.param.SupplierStoragesAddParam;
import vip.xiaonuo.supplier.modular.warehouse.storages.param.SupplierStoragesEditParam;
import vip.xiaonuo.supplier.modular.warehouse.storages.param.SupplierStoragesIdParam;
import vip.xiaonuo.supplier.modular.warehouse.storages.param.SupplierStoragesPageParam;
import vip.xiaonuo.supplier.modular.warehouse.storages.service.SupplierStoragesService;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import java.util.List;

/**
 * 仓库信息控制器
 *
 * @author Mr.wu
 * @date  2025/03/15 19:51
 */
@Tag(name = "仓库信息控制器")
@RestController
@Validated
public class SupplierStoragesController {

    @Resource
    private SupplierStoragesService supplierStoragesService;

    /**
     * 获取仓库信息分页
     *
     * @author Mr.wu
     * @date  2025/03/15 19:51
     */
    @Operation(summary = "获取仓库信息分页")
    @SaCheckPermission("/supplier/warehouse/storages/page")
    @GetMapping("/supplier/warehouse/storages/page")
    public CommonResult<Page<SupplierStorages>> page(SupplierStoragesPageParam supplierStoragesPageParam) {
        return CommonResult.data(supplierStoragesService.page(supplierStoragesPageParam));
    }

    /**
     * 添加仓库信息
     *
     * @author Mr.wu
     * @date  2025/03/15 19:51
     */
    @Operation(summary = "添加仓库信息")
    @CommonLog("添加仓库信息")
    @SaCheckPermission("/supplier/warehouse/storages/add")
    @PostMapping("/supplier/warehouse/storages/add")
    public CommonResult<String> add(@RequestBody @Valid SupplierStoragesAddParam supplierStoragesAddParam) {
        supplierStoragesService.add(supplierStoragesAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑仓库信息
     *
     * @author Mr.wu
     * @date  2025/03/15 19:51
     */
    @Operation(summary = "编辑仓库信息")
    @CommonLog("编辑仓库信息")
    @SaCheckPermission("/supplier/warehouse/storages/edit")
    @PostMapping("/supplier/warehouse/storages/edit")
    public CommonResult<String> edit(@RequestBody @Valid SupplierStoragesEditParam supplierStoragesEditParam) {
        supplierStoragesService.edit(supplierStoragesEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除仓库信息
     *
     * @author Mr.wu
     * @date  2025/03/15 19:51
     */
    @Operation(summary = "删除仓库信息")
    @CommonLog("删除仓库信息")
    @SaCheckPermission("/supplier/warehouse/storages/delete")
    @PostMapping("/supplier/warehouse/storages/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                                   List<SupplierStoragesIdParam> supplierStoragesIdParamList) {
        supplierStoragesService.delete(supplierStoragesIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取仓库信息详情
     *
     * @author Mr.wu
     * @date  2025/03/15 19:51
     */
    @Operation(summary = "获取仓库信息详情")
    @SaCheckPermission("/supplier/warehouse/storages/detail")
    @GetMapping("/supplier/warehouse/storages/detail")
    public CommonResult<SupplierStorages> detail(@Valid SupplierStoragesIdParam supplierStoragesIdParam) {
        return CommonResult.data(supplierStoragesService.detail(supplierStoragesIdParam));
    }
}
